<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use common\models\goods\GoodsAttr;

/* @var $this yii\web\View */
/* @var $searchModel common\models\GoodsAttrSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '商品属性';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="goods-attr-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]);  ?>

    <p>
        <?= Html::a('新建', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

<?php
    $typeMap=[''=>'不过滤',GoodsAttr::TYPE_SKU => '规格', GoodsAttr::TYPE_SPEC => '扩展属性'];
    
    echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'id',
            'name',
            [
                'attribute' => 'type',
                'filterType'=>GridView::FILTER_SELECT2,
                'filter'=>$typeMap, 
                'content' => function($data, $row) {
                    $typeMap=[GoodsAttr::TYPE_SKU => '规格', GoodsAttr::TYPE_SPEC => '扩展属性'];
                    return $typeMap[$data->type];
                },
            ],
            'usedAcount',
            //'input_type',
            // 'is_aliases',
            // 'is_upload_img',
            // 'is_color',
            // 'is_not_null',
            [
                'class' => 'yii\grid\ActionColumn',
                'buttons'=>[
                    'delete' => function ($url, $model, $key) {
                        return $model->usedAcount ==0 ? Html::a('<span class="glyphicon glyphicon-trash"></span>', $url,['data-confirm'=>'您确定要删除此项吗？','data-method'=>'post','data-pjax'=>0]) : '';
                    },
                ],
            ],
        ],
        'responsive' => true,
        'hover' => true
    ]);
?>

</div>
